/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Modelo;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

/**
 *
 * @author Alex
 */
public class ModelExperiencia implements Serializable{


    private Conection con = new Conection();
    private ResultSet rs;

    public ModelExperiencia(Conection con) {
        this.con = con;
    }

    public ResultSet getRs() {
        return rs;
    }

    public void setRs(ResultSet rs) {
        this.rs = rs;
    }

public LinkedList Experiencias(String codigo )throws SQLException{
	LinkedList listaExp=new LinkedList();
	PreparedStatement pstmt=null;
	ResultSet rs=null;
  	try{

  		pstmt=con.getCon().prepareStatement("select * from Experiencia where Experiencia.Aspirante_Id =" + codigo);
  		rs=pstmt.executeQuery();
  		while(rs.next()){
  			listaExp.add(Experiencia.Load(rs));

  		}
  	}finally{
 		if(rs!=null){
			rs.close();
		}
		if(pstmt!=null){
			pstmt.close();
			pstmt=null;
		}
	}

	return listaExp;
 }
  public void setNewExp(Experiencia exp) throws SQLException {
        if( !con.isConnect())
                throw new SQLException("no Hay Conexion");
            PreparedStatement pstmt=null;
            try{
                pstmt=con.getCon().prepareStatement("insert into Experiencia values(?,?,?,?,?)");
                pstmt.setString(1, exp.getCargo());
                pstmt.setString(2, exp.getJefe());
                pstmt.setString(3, exp.getTiempo());
                pstmt.setString(4, exp.getAspirante());
                pstmt.setString(5, exp.getEmpresa());
               ;
		
                
		pstmt.executeUpdate();

                }finally
                {
                    if( pstmt!=null )
                    pstmt.close();
                }


    }
    public boolean Eliminar(String codigo) throws Exception
      {

    try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();

         if (con.isConnect())
         {
             PreparedStatement stmt = con.getCon().prepareStatement("delete from Experiencia where Experiencia.Cargo= "+"'"+ codigo +"'");
               stmt.executeUpdate();
                return true;

            }
    }
    catch(SQLException ex) {
         System.out.println(ex);
    }
    catch(ClassNotFoundException ex) {
    System.out.println(ex);  }
    return false;
    }

}// fin clase model
